home *** CD-ROM | disk | FTP | other *** search
/ Network Supervisor's Toolkit / Network Supervisor's Toolkit.iso / tools / sockets / socket.c next >
Text File  |  1996-07-10  |  2KB  |  67 lines

  1. /* This program will list all open sockets in the Novell NetWare shell.
  2.  
  3.    This is done (inelegantly) by attempting to open each socket, then examining
  4.    the the function result.  If the result code is 0, the socket was opened,
  5.    meaning the socket was not previously opened.  If the result is 0xff, the
  6.    socket was already open.  A function result of 0xfe means the socket table
  7.    is full, and the program cannot continue.
  8.  
  9.                         Andy Stevens
  10.                         September 1, 1987
  11.  
  12. */
  13.  
  14.  
  15.  
  16.  
  17. #define SWAP( x )  ( (x >> 8) | (x << 8) )
  18. /* all references, other than in an Event Control Block, must be in hi-low
  19.    order, rather than the iAPX86 native hi-low order.  This macro simply
  20.    switches the hi and low order bytes of a two byte word. */
  21.  
  22. unsigned count = 0, total = 0;
  23.  
  24. void close_socket( unsigned socket )
  25. {
  26.     _BX = 1;
  27.     _DX = SWAP( socket );
  28.     __int__( 0x7A );
  29. }
  30.  
  31. void check_socket( unsigned socket )
  32. {
  33.     _AL =
  34.     _BX = 0;
  35.     _DX = SWAP( socket );
  36.     __int__( 0x7A );
  37.     switch( _AL ) {
  38.         case 0    : {        /* socket not previously opened */
  39.             close_socket( socket );
  40.             break;
  41.         }
  42.         case 0xFF : {        /* opened socket */
  43.             printf("\tSocket: %4X\n", count);
  44.             total++;
  45.             break;
  46.         }
  47.         case 0xFE : {        /* unable to continue */
  48.             printf("ERROR - SOCKET TABLE IS FULL");
  49.             exit( 1 );
  50.             break;
  51.         }
  52.     }
  53. }
  54.  
  55.  
  56.  
  57. main( void )
  58. {
  59.     printf( "\nChecking for open sockets...\n" );
  60.     printf( "(all sockets displayed in hex)\n\n" );
  61.  
  62.     for( count=0; count != 65535; count++ )
  63.         check_socket( count );
  64.  
  65.     printf( "\nTotal open sockets: %d\n", total );
  66. }
  67.